# -*- coding: utf-8 -*- 
#
# Description:
#
#  Definiton
#
#
#
# Changes:
#
# 2012-01-10
# Initial Commit
#
#
# Copyright 2010-2012, WyDev Team.
# Author: Polo35 (polo35580@hotmail.fr)
#
# Licenced under Academic Free License version 3.0
# Review WyGui README & LICENSE files for further details.

nname: 0
n 0(None)[return self.get_result_count()
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb75c566c>}
nname: 0
n 0(None)[return self.get_title()
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb75c568c>}
nname: 303
n 303(None)[return None
]:
	i: 278(), 292()
	o: 

nname: 292
n 292(None)[self.search()
]:
	i: 269(t)
	o: 303()

nname: 278
n 278(None)[self.ask_pattern()
]:
	i: 269(f)
	o: 303()

nname: 269
n 269(self.pattern)[]:
	i: 212(), 268()
	o: 278(f), 292(t)

nname: 268
n 268(None)[]:
	i: 0(t)
	o: 269()

nname: 212
n 212(None)[mn = Task(self._move_navigator)
mn.delay = config.HMI_BASE['search_navigator_delay']
self.move_navigator = mn.start
self.move_navigator_task = mn
]:
	i: 0(f)
	o: 269()

nname: 0
n 0(hasattr(self, 'move_navigator'))[self.eventhandler = SearchMenuEventHandler(self)
Menu.__init__(self, name, type=type, universe=universe)
self.kbd = SearchKeyboardWindow(_('Search'), text='', confirm_action=self.search, search_menu=self)
self.pattern = pattern
self.navigator = pygui_globs['menustack'].get_navigator()
self.positions_dict = dict()
self.pattern = None
self._wil_result = None
def self._getitems_keywords['result_count']():
	return self.get_result_count()

def self._getitems_keywords['title']():
	return self.get_title()

self.show()
]:
	i: 
	o: 212(f), 268(t)

nname: 303
n 303(None)[return None
]:
	i: 0()
	o: 

nname: 0
n 0(None)[self.eventhandler = SearchMenuEventHandler(self)
Menu.__init__(self, name, type=type, universe=universe)
self.kbd = SearchKeyboardWindow(_('Search'), text='', confirm_action=self.search, search_menu=self)
self.pattern = pattern
self.navigator = pygui_globs['menustack'].get_navigator()
self.positions_dict = dict()
self.pattern = None
self._wil_result = None
def self._getitems_keywords['result_count']():
	return self.get_result_count()

def self._getitems_keywords['title']():
	return self.get_title()

self.show()
if not hasattr(self, 'move_navigator'):
	mn = Task(self._move_navigator)
	mn.delay = config.HMI_BASE['search_navigator_delay']
	self.move_navigator = mn.start
	self.move_navigator_task = mn
if not self.pattern:
	self.ask_pattern()
else:
	self.search()
]:
	i: 
	o: 303()

nname: 0
n 0(None)[self.eventhandler = SearchMenuEventHandler(self)
Menu.__init__(self, name, type=type, universe=universe)
self.kbd = SearchKeyboardWindow(_('Search'), text='', confirm_action=self.search, search_menu=self)
self.pattern = pattern
self.navigator = pygui_globs['menustack'].get_navigator()
self.positions_dict = dict()
self.pattern = None
self._wil_result = None
def self._getitems_keywords['result_count']():
	return self.get_result_count()

def self._getitems_keywords['title']():
	return self.get_title()

self.show()
if not hasattr(self, 'move_navigator'):
	mn = Task(self._move_navigator)
	mn.delay = config.HMI_BASE['search_navigator_delay']
	self.move_navigator = mn.start
	self.move_navigator_task = mn
if not self.pattern:
	self.ask_pattern()
else:
	self.search()
return None
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb75ba5ec>}
nname: 324
n 324(None)[return None
]:
	i: 116(), 214()
	o: 

nname: 214
n 214(None)[no_result_item = Item(name=_("No results for '%s'") % self.pattern, type_='info')
self.set_items([no_result_item], 'main_list')
louie_send('result_count', sender=self, value=self.get_result_count())
louie_send('title', sender=self, value=self.get_title())
]:
	i: 0(f)
	o: 324()

nname: 116
n 116(None)[self.set_items(self._wil_result, 'main_list')
self.select(0, force_select=True)
louie_send('result_count', sender=self, value=self.get_result_count())
louie_send('title', sender=self, value=self.get_title())
]:
	i: 0(t)
	o: 324()

nname: 0
n 0(len(self._wil_result))[self.kbd.hide()
self.pattern = self.kbd.text
self._wil_result = WindowedItemList(None, menu=self.navigator, universe=self.universe, browse_fn=wm_search, pattern=self.pattern)
log.debug('Search(%s): %s', self.pattern, self._wil_result)
]:
	i: 
	o: 116(t), 214(f)

nname: 0
n 0(None)[self.kbd.hide()
self.pattern = self.kbd.text
self._wil_result = WindowedItemList(None, menu=self.navigator, universe=self.universe, browse_fn=wm_search, pattern=self.pattern)
log.debug('Search(%s): %s', self.pattern, self._wil_result)
if len(self._wil_result):
	self.set_items(self._wil_result, 'main_list')
	self.select(0, force_select=True)
	louie_send('result_count', sender=self, value=self.get_result_count())
	louie_send('title', sender=self, value=self.get_title())
else:
	no_result_item = Item(name=_("No results for '%s'") % self.pattern, type_='info')
	self.set_items([no_result_item], 'main_list')
	louie_send('result_count', sender=self, value=self.get_result_count())
	louie_send('title', sender=self, value=self.get_title())
return None
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb75ba8ec>}
nname: 39
n 39(None)[return _('Search')
]:
	i: 9(), 29()
	o: 

nname: 29
n 29(None)[]:
	i: 0(f)
	o: 39()

nname: 9
n 9(None)[]:
	i: 0(t)
	o: 39()

nname: 0
n 0(self.pattern)[]:
	i: 
	o: 9(t), 29(f)

nname: 0
n 0(None)[if self.pattern:
	pass
return _('Search')
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb75b85cc>}
nname: 97
n 97(None)[return res_count
]:
	i: 72(JA), 86(), 90()
	o: 

nname: 90
n 90(None)[res_count = '0/0'
]:
	i: 0(f)
	o: 97()

nname: 86
n 86(None)[]:
	i: 15&58(f)
	o: 97()

nname: 72
n 72(None)[res_count += ' ...'
]:
	i: 15&58(t)
	o: 97(JA)

nname: 15&58
n 15&58(self._wil_result and not self._wil_result.end_reached)[res_count = '%s/%s' % (self.selected_pos + 1, len(self['main_list']))
]:
	i: 0(t)
	o: 72(t), 86(f)

nname: 0
n 0(self.selected_pos >= 0)[]:
	i: 
	o: 15&58(t), 90(f)

nname: 0
n 0(None)[if self.selected_pos >= 0:
	res_count = '%s/%s' % (self.selected_pos + 1, len(self['main_list']))
	if self._wil_result and not self._wil_result.end_reached:
		res_count += ' ...'
else:
	res_count = '0/0'
return res_count
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb75b87cc>}
nname: 0
n 0(None)[sel = self.selected
pos = get_browse_position(sel.wymedia_resource, wymedia_sorting, dict(universe=self.universe))
sel.menu = self.navigator
self.navigator.go_to_item(sel, 'event_right', pos)
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb75b8eac>}
nname: 93
n 93(None)[]:
	i: 50(), 92()
	o: 

nname: 92
n 92(None)[]:
	i: 0&33&43(f)
	o: 93()

nname: 50
n 50(None)[louie_send('result_count', sender=self, value=self.get_result_count())
self.move_navigator()
]:
	i: 0&33&43(t)
	o: 93()

nname: 0&33&43
n 0&33&43(ret is not False and self.navigator or force_select)[ret = Menu.select(self, item, list_name)
]:
	i: 
	o: 50(t), 92(f)

nname: 0&33&43
n 0&33&43(None)[ret = Menu.select(self, item, list_name)
if ret is not False and self.navigator or force_select:
	louie_send('result_count', sender=self, value=self.get_result_count())
	self.move_navigator()
]:
	i: 
	o: 

self.nodes: {'0&33&43': <unpyclib.structure.node instance at 0xb75b8e6c>}
nname: 0
n 0(None)[return Menu.show(self, False)
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb75b842c>}
nname: 0
n 0(None)[pygui_globs['menustack'].back_to_menu(self.navigator)
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb75b876c>}
nname: 0
n 0(None)[self.kbd.show()
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb75b83ec>}
nname: 0
n 0(None)[self.move_navigator_task.stop()
self.selected.execute()
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb75b888c>}
nname: 6
n 6(None)[__doc__ = ' Media search Menu '
def __init__(self, name='Search menu', eventhandler=None, type='media_search', pattern=None, universe=None):
	self.eventhandler = SearchMenuEventHandler(self)
	Menu.__init__(self, name, type=type, universe=universe)
	self.kbd = SearchKeyboardWindow(_('Search'), text='', confirm_action=self.search, search_menu=self)
	self.pattern = pattern
	self.navigator = pygui_globs['menustack'].get_navigator()
	self.positions_dict = dict()
	self.pattern = None
	self._wil_result = None
	def self._getitems_keywords['result_count']():
		return self.get_result_count()

	def self._getitems_keywords['title']():
		return self.get_title()

	self.show()
	if not hasattr(self, 'move_navigator'):
		mn = Task(self._move_navigator)
		mn.delay = config.HMI_BASE['search_navigator_delay']
		self.move_navigator = mn.start
		self.move_navigator_task = mn
	if not self.pattern:
		self.ask_pattern()
	else:
		self.search()
	return None

def search(self, kbd):
	self.kbd.hide()
	self.pattern = self.kbd.text
	self._wil_result = WindowedItemList(None, menu=self.navigator, universe=self.universe, browse_fn=wm_search, pattern=self.pattern)
	log.debug('Search(%s): %s', self.pattern, self._wil_result)
	if len(self._wil_result):
		self.set_items(self._wil_result, 'main_list')
		self.select(0, force_select=True)
		louie_send('result_count', sender=self, value=self.get_result_count())
		louie_send('title', sender=self, value=self.get_title())
	else:
		no_result_item = Item(name=_("No results for '%s'") % self.pattern, type_='info')
		self.set_items([no_result_item], 'main_list')
		louie_send('result_count', sender=self, value=self.get_result_count())
		louie_send('title', sender=self, value=self.get_title())
	return None

def get_title(self):
	if self.pattern:
		pass
	return _('Search')

def get_result_count(self):
	if self.selected_pos >= 0:
		res_count = '%s/%s' % (self.selected_pos + 1, len(self['main_list']))
		if self._wil_result and not self._wil_result.end_reached:
			res_count += ' ...'
	else:
		res_count = '0/0'
	return res_count

def _move_navigator(self):
	sel = self.selected
	pos = get_browse_position(sel.wymedia_resource, wymedia_sorting, dict(universe=self.universe))
	sel.menu = self.navigator
	self.navigator.go_to_item(sel, 'event_right', pos)

def select(self, item, list_name=None, force_select=False):
	ret = Menu.select(self, item, list_name)
	if ret is not False and self.navigator or force_select:
		louie_send('result_count', sender=self, value=self.get_result_count())
		self.move_navigator()

def show(self):
	return Menu.show(self, False)

def hide(self):
	pygui_globs['menustack'].back_to_menu(self.navigator)

def ask_pattern(self):
	self.kbd.show()

def execute_selected(self):
	self.move_navigator_task.stop()
	self.selected.execute()

]:
	i: 
	o: 

self.nodes: {6: <unpyclib.structure.node instance at 0xb75b2bec>}
nname: 0
n 0(None)[from __future__ import absolute_import
__all__ = ['SearchMenu']
from peewee.debug import GET_LOGGER
from peewee.messages import send as louie_send
from peewee.notifier import Task
from pygui.eventmanager.menus import SearchMenuEventHandler
from pygui.item.mediaitem.core import wymedia_sorting
from pygui.item.mediaitem.progressive_result import WindowedItemList
from pygui.shared import pygui_globs
from pygui.menu.menu import Menu
from pygui.window import SearchKeyboardWindow
from pygui.item.core import Item
import pygui.config as config
from wymedia.wmplus import get_browse_position, search as wm_search
log = GET_LOGGER(__name__)
class SearchMenu(Menu):
	__doc__ = ' Media search Menu '
	def __init__(self, name='Search menu', eventhandler=None, type='media_search', pattern=None, universe=None):
		self.eventhandler = SearchMenuEventHandler(self)
		Menu.__init__(self, name, type=type, universe=universe)
		self.kbd = SearchKeyboardWindow(_('Search'), text='', confirm_action=self.search, search_menu=self)
		self.pattern = pattern
		self.navigator = pygui_globs['menustack'].get_navigator()
		self.positions_dict = dict()
		self.pattern = None
		self._wil_result = None
		def self._getitems_keywords['result_count']():
			return self.get_result_count()

		def self._getitems_keywords['title']():
			return self.get_title()

		self.show()
		if not hasattr(self, 'move_navigator'):
			mn = Task(self._move_navigator)
			mn.delay = config.HMI_BASE['search_navigator_delay']
			self.move_navigator = mn.start
			self.move_navigator_task = mn
		if not self.pattern:
			self.ask_pattern()
		else:
			self.search()
		return None

	def search(self, kbd):
		self.kbd.hide()
		self.pattern = self.kbd.text
		self._wil_result = WindowedItemList(None, menu=self.navigator, universe=self.universe, browse_fn=wm_search, pattern=self.pattern)
		log.debug('Search(%s): %s', self.pattern, self._wil_result)
		if len(self._wil_result):
			self.set_items(self._wil_result, 'main_list')
			self.select(0, force_select=True)
			louie_send('result_count', sender=self, value=self.get_result_count())
			louie_send('title', sender=self, value=self.get_title())
		else:
			no_result_item = Item(name=_("No results for '%s'") % self.pattern, type_='info')
			self.set_items([no_result_item], 'main_list')
			louie_send('result_count', sender=self, value=self.get_result_count())
			louie_send('title', sender=self, value=self.get_title())
		return None

	def get_title(self):
		if self.pattern:
			pass
		return _('Search')

	def get_result_count(self):
		if self.selected_pos >= 0:
			res_count = '%s/%s' % (self.selected_pos + 1, len(self['main_list']))
			if self._wil_result and not self._wil_result.end_reached:
				res_count += ' ...'
		else:
			res_count = '0/0'
		return res_count

	def _move_navigator(self):
		sel = self.selected
		pos = get_browse_position(sel.wymedia_resource, wymedia_sorting, dict(universe=self.universe))
		sel.menu = self.navigator
		self.navigator.go_to_item(sel, 'event_right', pos)

	def select(self, item, list_name=None, force_select=False):
		ret = Menu.select(self, item, list_name)
		if ret is not False and self.navigator or force_select:
			louie_send('result_count', sender=self, value=self.get_result_count())
			self.move_navigator()

	def show(self):
		return Menu.show(self, False)

	def hide(self):
		pygui_globs['menustack'].back_to_menu(self.navigator)

	def ask_pattern(self):
		self.kbd.show()

	def execute_selected(self):
		self.move_navigator_task.stop()
		self.selected.execute()



]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb75a856c>}
from __future__ import absolute_import
__all__ = ['SearchMenu']
from peewee.debug import GET_LOGGER
from peewee.messages import send as louie_send
from peewee.notifier import Task
from pygui.eventmanager.menus import SearchMenuEventHandler
from pygui.item.mediaitem.core import wymedia_sorting
from pygui.item.mediaitem.progressive_result import WindowedItemList
from pygui.shared import pygui_globs
from pygui.menu.menu import Menu
from pygui.window import SearchKeyboardWindow
from pygui.item.core import Item
import pygui.config as config
from wymedia.wmplus import get_browse_position, search as wm_search
log = GET_LOGGER(__name__)
class SearchMenu(Menu):
	__doc__ = ' Media search Menu '
	def __init__(self, name='Search menu', eventhandler=None, type='media_search', pattern=None, universe=None):
		self.eventhandler = SearchMenuEventHandler(self)
		Menu.__init__(self, name, type=type, universe=universe)
		self.kbd = SearchKeyboardWindow(_('Search'), text='', confirm_action=self.search, search_menu=self)
		self.pattern = pattern
		self.navigator = pygui_globs['menustack'].get_navigator()
		self.positions_dict = dict()
		self.pattern = None
		self._wil_result = None
		def self._getitems_keywords['result_count']():
			return self.get_result_count()

		def self._getitems_keywords['title']():
			return self.get_title()

		self.show()
		if not hasattr(self, 'move_navigator'):
			mn = Task(self._move_navigator)
			mn.delay = config.HMI_BASE['search_navigator_delay']
			self.move_navigator = mn.start
			self.move_navigator_task = mn
		if not self.pattern:
			self.ask_pattern()
		else:
			self.search()
		return None

	def search(self, kbd):
		self.kbd.hide()
		self.pattern = self.kbd.text
		self._wil_result = WindowedItemList(None, menu=self.navigator, universe=self.universe, browse_fn=wm_search, pattern=self.pattern)
		log.debug('Search(%s): %s', self.pattern, self._wil_result)
		if len(self._wil_result):
			self.set_items(self._wil_result, 'main_list')
			self.select(0, force_select=True)
			louie_send('result_count', sender=self, value=self.get_result_count())
			louie_send('title', sender=self, value=self.get_title())
		else:
			no_result_item = Item(name=_("No results for '%s'") % self.pattern, type_='info')
			self.set_items([no_result_item], 'main_list')
			louie_send('result_count', sender=self, value=self.get_result_count())
			louie_send('title', sender=self, value=self.get_title())
		return None

	def get_title(self):
		if self.pattern:
			pass
		return _('Search')

	def get_result_count(self):
		if self.selected_pos >= 0:
			res_count = '%s/%s' % (self.selected_pos + 1, len(self['main_list']))
			if self._wil_result and not self._wil_result.end_reached:
				res_count += ' ...'
		else:
			res_count = '0/0'
		return res_count

	def _move_navigator(self):
		sel = self.selected
		pos = get_browse_position(sel.wymedia_resource, wymedia_sorting, dict(universe=self.universe))
		sel.menu = self.navigator
		self.navigator.go_to_item(sel, 'event_right', pos)

	def select(self, item, list_name=None, force_select=False):
		ret = Menu.select(self, item, list_name)
		if ret is not False and self.navigator or force_select:
			louie_send('result_count', sender=self, value=self.get_result_count())
			self.move_navigator()

	def show(self):
		return Menu.show(self, False)

	def hide(self):
		pygui_globs['menustack'].back_to_menu(self.navigator)

	def ask_pattern(self):
		self.kbd.show()

	def execute_selected(self):
		self.move_navigator_task.stop()
		self.selected.execute()



